package com.crack.nga2.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.crack.nga2.R;
import com.crack.nga2.custom.HeadLayoutImpl;
import com.crack.nga2.custom.ILoadingLayout;
import com.crack.nga2.entity.Task;
import com.crack.nga2.utils.GlobalConst;
import com.crack.nga2.utils.HttpParams;
import com.crack.nga2.volley.TaskRequest;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TaskActivity extends BaseActivity {
    private ILoadingLayout header;
    private TaskAdapter adapter;
    private Map<Integer, Task> tasks = new HashMap<>();
    private RequestQueue mQueue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task);
        mQueue = NgaApplication.getQueue();
        View view = findViewById(R.id.pull_header);
        header = new HeadLayoutImpl(this, view);
        header.startRefresh();
        ListView listView = (ListView) findViewById(R.id.listView);
        adapter = new TaskAdapter();
        listView.setAdapter(adapter);
        getData();
    }

    private void getData() {
        String url = GlobalConst.BASE_URL + "nuke.php?";
        HttpParams params = new HttpParams();
        params.put("__lib", "mission");
        params.put("__act", "get");
        params.put("event", 1);
        params.put("available", 1);
        params.put("lite", "js");
        mQueue.add(new TaskRequest(Request.Method.GET, url,
                new Response.Listener<List<Task>>() {
                    @Override
                    public void onResponse(List<Task> response) {

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }));
    }

    public void doClick(View view) {
        switch (view.getId()) {
            case R.id.action_return:
                finishForAnimation();
                break;
        }
    }

    private class TaskAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return tasks.size();
        }

        @Override
        public Object getItem(int position) {
            return tasks.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return null;
        }
    }
}
